package cn.afactory.tygz.model;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created with Android Studio.
 * Title:SecondGoodsInfo
 * Description:
 * Copyright:Copyright (c) 2015
 * Company:和平必胜、正义必胜、人民必胜
 * Author:炎黄子孙
 * Date:15/9/11
 * Time:下午3:44
 * Version 1.0
 */
public class ApartmentInfo implements Serializable{
    private static final long serialVersionUID = 3246451692600706144L;

    public long id;

    public String name;

    public String iconPath;

    public double score;

    public double price;

    public int type;

    public double distance;

    public String typeName;

    public String address;

    public double lat;

    public double lng;

    public String tel;

    public String intro;

    public String notice;

    public String contactName;

    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static ApartmentInfo deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    /**
     * 反序列化函数，用于从json节点对象反序列化本类型实例
     */
    public static ApartmentInfo deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            ApartmentInfo result = new ApartmentInfo();

            result.type = json.optInt("type");

            result.id = json.optLong("id");

            if (!json.isNull("iconPath")) {
                result.iconPath = json.optString("iconPath", null);
            }

            if (!json.isNull("name")) {
                result.name = json.optString("name", null);
            }

            result.score = json.optDouble("score");

            result.price = json.optDouble("price");

            result.distance = json.optDouble("distance");

            if (!json.isNull("typeName")) {
                result.typeName = json.optString("typeName", null);
            }

            if (!json.isNull("address")) {
                result.address = json.optString("address", null);
            }

            if (!json.isNull("tel")) {
                result.tel = json.optString("tel", null);
            }

            if (!json.isNull("intro")) {
                result.intro = json.optString("intro", null);
            }

            if (!json.isNull("notice")) {
                result.notice = json.optString("notice", null);
            }

            if (!json.isNull("contactName")) {
                result.contactName = json.optString("contactName", null);
            }

            result.lat = json.optDouble("lat");
            result.lng = json.optDouble("lng");

            return result;
        }
        return null;
    }
}
